package com.abel.bigwater.dataserver.model.qdies

import com.abel.bigwater.data.BcdString
import io.netty.buffer.Unpooled
import org.junit.Assert.assertEquals
import org.junit.Test
import org.slf4j.LoggerFactory

class MainAskHistTest {
    @Test
    fun fillAsk485Hist() {
        val buf = Unpooled.buffer()
        val p = MainPacket().apply {
            address = BcdString(byteArrayOf(12, 0, 0, 1), true)
            func = FuncType.Ask485Hist
            data = MainAsk485HistData().also {
                it.internalAddr = 1
                it.maxRows = 720
            }

            fill(buf)
        }

        val str = BcdString.create(buf, buf.readableBytes()).bcdString
        lgr.info(str)
        assertEquals("ask 485 hist", DEMO_ASK_485_HIST, str)
    }

    @Test
    fun fillAskAnalogNow() {
        val buf = Unpooled.buffer()
        val p = MainPacket().apply {
            address = BcdString(byteArrayOf(12, 0, 0, 1), true)
            func = FuncType.AskAnalogHist
            data = MainAskAnalogHistData().also {
                it.internalAddr = 1
                it.maxRows = 720
            }

            fill(buf)
        }

        val str = BcdString.create(buf, buf.readableBytes()).bcdString
        lgr.info(str)
        assertEquals("ask analog hist", DEMO_ASK_ANALOG_HIST, str)
    }

    @Test
    fun fillAskPulseNow() {
        val buf = Unpooled.buffer()
        val p = MainPacket().apply {
            address = BcdString(byteArrayOf(12, 0, 0, 1), true)
            func = FuncType.AskPulseHist
            data = MainAskPulseHistData().also {
                it.internalAddr = 1
                it.maxRows = 720
            }

            fill(buf)
        }

        val str = BcdString.create(buf, buf.readableBytes()).bcdString
        lgr.info(str)
        assertEquals("ask pulse hist", DEMO_ASK_PULSE_HIST, str)
    }

    companion object {
        private val lgr = LoggerFactory.getLogger(MainAskHistTest::class.java)

        const val DEMO_ASK_485_HIST = "68120000011b030102d09416"

        const val DEMO_ASK_ANALOG_HIST = "68120000011c030102d09316"

        const val DEMO_ASK_PULSE_HIST = "68120000011d030102d09216"
    }
}